<?php

namespace App\Http\Controllers\Information;

use App\Common\Utils\JsonResponse;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

class ArchivesController extends Controller
{
    /** @var \App\Services\System\LogService $logService */
    private $logService;
    /** @var \App\Services\Information\ArchivesService $archivesService */
    private $archivesService;

    /**
    * Create a new controller instance.
    *
    * @return void
    */
    public function __construct()
    {
        parent::__construct();
        $this->middleware('auth');
        $this->logService = app('logService');
        $this->archivesService = app('archivesService');
    }

    /**
     * @Description: 教师信息角色页面处理
     * @Author: kzj
     * @datetime: 2022-11-18
     */
    public function index(Request $request)
    {
        try
        {
            $user = Auth::user();
            $role = $user->cur_role_id;
            //管理员
            if(in_array($role, [SYSTEM_ROLE, ADMIN_ROLE]) || is_check(206) || is_check(308) || is_check(309)) {
                return view('systems.teacher.index');
            } else {
                return view('information.archives.index');
            }
        }
        catch(\Exception $e)
        {
            Log::error($e);
            return $this->error($e);
        }
    }

    /**
     * @Description: 添加职务数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function addPosition(Request $request)
    {
        try{
            $result = $this->archivesService->addPosition($request->all());
            $this->logService->log('303', '添加职务数据', '添加职务数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 添加学习经历数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function addLearnHistory(Request $request)
    {
        try{
            $result = $this->archivesService->addLearnHistory($request->all());
            $this->logService->log('303', '添加学习经历数据', '添加学习经历数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 添加工作经历数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function addWorkHistory(Request $request)
    {
        try{
            $result = $this->archivesService->addWorkHistory($request->all());
            $this->logService->log('303', '添加工作经历数据', '添加工作经历数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 添加年度考核数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function addAssessment(Request $request)
    {
        try{
            $result = $this->archivesService->addAssessment($request->all());
            $this->logService->log('303', '添加年度考核数据', '添加年度考核数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 编辑职务数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function editPosition(Request $request)
    {
        try{
            $result = $this->archivesService->editPosition($request->all());
            $this->logService->log('304', '编辑职务数据', '编辑职务数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 编辑学习经历数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function editLearnHistory(Request $request)
    {
        try{
            $result = $this->archivesService->editLearnHistory($request->all());
            $this->logService->log('304', '编辑学习经历数据', '编辑学习经历数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 编辑工作经历数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function editWorkHistory(Request $request)
    {
        try{
            $result = $this->archivesService->editWorkHistory($request->all());
            $this->logService->log('304', '编辑工作经历数据', '编辑工作经历数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 编辑年度考核数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function editAssessment(Request $request)
    {
        try{
            $result = $this->archivesService->editAssessment($request->all());
            $this->logService->log('304', '编辑年度考核数据', '编辑年度考核数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 删除职务数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function delPosition(Request $request)
    {
        try{
            $result = $this->archivesService->delPosition($request->all());
            $this->logService->log('306', '删除职务数据', '删除职务数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 删除学习经历数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function delLearnHistory(Request $request)
    {
        try{
            $result = $this->archivesService->delLearnHistory($request->all());
            $this->logService->log('306', '删除学习经历数据', '删除学习经历数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 删除工作经历数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function delWorkHistory(Request $request)
    {
        try{
            $result = $this->archivesService->delWorkHistory($request->all());
            $this->logService->log('306', '删除工作经历数据', '删除工作经历数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 删除年度考核数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function delAssessment(Request $request)
    {
        try{
            $result = $this->archivesService->delAssessment($request->all());
            $this->logService->log('306', '删除年度考核数据', '删除年度考核数据');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }


    /**
     * @Description: 审核基本信息数据
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function getCheckInfo(Request $request)
    {
        try{
            $result = $this->archivesService->getCheckInfo($request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 基本信息编辑提交
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function subBasicInfo(Request $request)
    {
        try{
            $result = $this->archivesService->subBasicInfo($request->all());
            $this->logService->log('307', '提交基本信息更新', '提交基本信息更新');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * @Description: 基本信息编辑审核提交
     * @Author: kzj
     * @datetime: 2023-03-31
     */
    public function subCheckBasicInfo(Request $request)
    {
        try{
            $result = $this->archivesService->subCheckBasicInfo($request->all());
            $this->logService->log('308', '提交基本信息更新', '提交基本信息更新');
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

}
